home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
asmexam.arc
/
ASCIIBIN.LST
< prev
next >
Wrap
File List
|
1984-07-10
|
7KB
|
207 lines
The Microsoft MACRO Assembler 07-10-84 PAGE 1-1
'ASCBIN - ASCII to binary conversion'
name ascbin
page 55,132
title 'ASCBIN - ASCII to binary conversion'
comment *
This program contains a pair of routines to convert
either decimal or hexidecimal ascii strings
to 32 bit binary integers
The main prog should load si with the address of the string
the proc leaves the 32 bit result in DX,CX
*
0000 cseg segment para
assume cs:cseg,ds:cseg,ss:cseg
0000 31 32 33 7A 7A 7A decnum: db '123','zzzz' ; z's are for extra locations
7A
0007 31 61 65 7A 7A 7A hexnum: db '1ae','zzzz'
7A
0100 org 100h
0100 main proc near
0100 8C C8 mov ax,cs
0102 8E D8 mov ds,ax ; these two statements set up ds reg for debug
0104 8D 36 0000 R lea si,decnum
0108 E8 0114 R call decbin
010B 8D 36 0007 R lea si,hexnum
010F E8 017D R call hexbin
0112 CD 20 int 20h
0114 main endp
0114 decbin proc near
0114 33 C9 xor cx,cx
0116 33 D2 xor dx,dx
0118 BB FFFF mov bx,-1
011B 8A 04 mov al,[si]
011D 3C 2B cmp al,'+'
011F 75 04 jne decbin1
0121 46 inc si
0122 EB 08 90 jmp decbin2
0125 decbin1:
0125 3C 2D cmp al,'-'
0127 75 03 jne decbin2
0129 32 FF xor bh,bh
012B 46 inc si
The Microsoft MACRO Assembler 07-10-84 PAGE 1-2
'ASCBIN - ASCII to binary conversion'
012C decbin2:
012C AC lodsb
012D 0A C0 or al,al
012F 74 3C jz decbin8
0131 3C 2E cmp al,'.'
0133 74 2E jz decbin4
0135 3C 39 cmp al,'9'
0137 77 32 ja decbin7
0139 3C 30 cmp al,'0'
013B 72 2E jb decbin7
013D 0A DB or bl,bl
013F 78 02 js decbin3
0141 FE C3 inc bl
0143 decbin3:
0143 50 push ax
0144 8B F9 mov di,cx
0146 8B C2 mov ax,dx
0148 D1 E1 shl cx,1
014A D1 D2 rcl dx,1
014C D1 E1 shl cx,1
014E D1 D2 rcl dx,1
0150 03 CF add cx,di
0152 13 D0 adc dx,ax
0154 D1 E1 shl cx,1
0156 D1 D2 rcl dx,1
0158 58 pop ax
0159 25 000F and ax,0fh
015C 03 C8 add cx,ax
015E 83 D2 00 adc dx,0
0161 EB C9 jmp decbin2
0163 decbin4:
0163 0A DB or bl,bl
0165 79 04 jns decbin7
0167 32 DB xor bl,bl
0169 EB C1 jmp decbin2
016B decbin7:
016B F9 stc
016C C3 ret
016D decbin8:
016D 0A FF or bh,bh
016F 75 0A jnz decbin9
0171 F7 D1 not cx
0173 F7 D2 not dx
0175 83 C1 01 add cx,1
0178 83 D2 00 adc dx,0
The Microsoft MACRO Assembler 07-10-84 PAGE 1-3
'ASCBIN - ASCII to binary conversion'
017B decbin9:
017B F8 clc
017C C3 ret
017D decbin endp
017D hexbin proc near
017D 33 C9 xor cx,cx
017F 33 D2 xor dx,dx
0181 hexbin1:
0181 AC lodsb
0182 0A C0 or al,al
0184 74 2D jz hexbin8
0186 3C 30 cmp al,'0'
0188 72 27 jb hexbin7
018A 3C 39 cmp al,'9'
018C 76 0C jbe hexbin3
018E hexbin2:
018E 0C 20 or al,20h
0190 3C 66 cmp al,'f'
0192 77 1D ja hexbin7
0194 3C 61 cmp al,'a'
0196 72 19 jb hexbin7
0198 04 09 add al,9
019A hexbin3:
019A D1 E1 shl cx,1
019C D1 D2 rcl dx,1
019E D1 E1 shl cx,1
01A0 D1 D2 rcl dx,1
01A2 D1 E1 shl cx,1
01A4 D1 D2 rcl dx,1
01A6 D1 E1 shl cx,1
01A8 D1 D2 rcl dx,1
01AA 25 000F and ax,0fh
01AD 0B C8 or cx,ax
01AF EB D0 jmp hexbin1
01B1 hexbin7:
01B1 F9 stc
01B2 C3 ret
01B3 hexbin8:
01B3 F8 clc
01B4 C3 ret
01B5 hexbin endp
The Microsoft MACRO Assembler 07-10-84 PAGE 1-4
'ASCBIN - ASCII to binary conversion'
01B5 cseg ends
end main
The Microsoft MACRO Assembler 07-10-84 PAGE Symbols-1
'ASCBIN - ASCII to binary conversion'
Segments and groups:
N a m e Size align combine class
CSEG . . . . . . . . . . . . . . 01B5 PARA NONE
Symbols:
N a m e Type Value Attr
DECBIN . . . . . . . . . . . . . N PROC 0114 CSEG Length =0069
DECBIN1. . . . . . . . . . . . . L NEAR 0125 CSEG
DECBIN2. . . . . . . . . . . . . L NEAR 012C CSEG
DECBIN3. . . . . . . . . . . . . L NEAR 0143 CSEG
DECBIN4. . . . . . . . . . . . . L NEAR 0163 CSEG
DECBIN7. . . . . . . . . . . . . L NEAR 016B CSEG
DECBIN8. . . . . . . . . . . . . L NEAR 016D CSEG
DECBIN9. . . . . . . . . . . . . L NEAR 017B CSEG
DECNUM . . . . . . . . . . . . . L NEAR 0000 CSEG
HEXBIN . . . . . . . . . . . . . N PROC 017D CSEG Length =0038
HEXBIN1. . . . . . . . . . . . . L NEAR 0181 CSEG
HEXBIN2. . . . . . . . . . . . . L NEAR 018E CSEG
HEXBIN3. . . . . . . . . . . . . L NEAR 019A CSEG
HEXBIN7. . . . . . . . . . . . . L NEAR 01B1 CSEG
HEXBIN8. . . . . . . . . . . . . L NEAR 01B3 CSEG
HEXNUM . . . . . . . . . . . . . L NEAR 0007 CSEG
MAIN . . . . . . . . . . . . . . N PROC 0100 CSEG Length =0014
Warning Severe
Errors Errors
0 0